package cn.skyquant.quant4j.jforex.strategy.yasha;

import cn.skyquant.quant4j.api.enums.BorkerType;
import cn.skyquant.quant4j.api.forex.ForexServiceProxy;
import cn.skyquant.quant4j.jforex.sdk.strategy2.InstrumentConfig;
import cn.skyquant.quant4j.jforex.sdk.strategy2.MultiConfigStrategy;
import cn.skyquant.quant4j.jforex.sdk.strategy2.QuantStrategy;
import cn.skyquant.quant4j.sdk.enums.TradeDirection;
import cn.skyquant.quant4j.sdk.util.constant.EAConstants;
import cn.skyquant.quant4j.sdk.util.time.CalendarUtils;
import com.dukascopy.api.*;

/**
 * 夜叉
 * 动态点位逆市加仓策略
 *
 * @author harley-dog
 */
@Library("quant4j-api.jar;quant4j-sdk.jar;quant4j-jforex-sdk.jar;httpclient-4.5.6.jar;httpcore-4.4.10.jar;fastjson-1.2.49.jar;commons-codec-1.11.jar")
public class Yasha extends MultiConfigStrategy {
    @Configurable("0:货币,方向,倍率")
    public String str0 = "EURUSD_A_1";
    @Configurable("1:货币,方向,倍率")
    public String str1 = "";
    @Configurable("2:货币,方向,倍率")
    public String str2 = "";
    @Configurable("3:货币,方向,倍率")
    public String str3 = "";
    @Configurable("4:货币,方向,倍率")
    public String str4 = "";
    @Configurable("5:货币,方向,倍率")
    public String str5 = "";
    @Configurable("6:货币,方向,倍率")
    public String str6 = "";

    ForexServiceProxy forexServiceProxy;

    @Override
    protected void init(InitEntity initEntity) {
        forexServiceProxy = new ForexServiceProxy(account.getAccountId(), BorkerType.DUKASCOPY);
        String[] strArr = {str0, str1, str2, str3, str4, str5, str6};
        for (int i = 0; i < strArr.length; i++) {
            if (strArr[i] != null && strArr[i].trim().length() > 0) {
                String[] s = strArr[i].split(EAConstants.split);
                if (s.length == 3
                        && s[0].trim().length() > 0
                        && s[1].trim().length() > 0
                        && s[2].trim().length() > 0) {
                    Instrument instrument = Instrument.valueOf(s[0]);
                    if (instrument == null) {
                        warn("%s is not a instrument",
                                "%s 不是一个货币",
                                s[0]);
                        continue;
                    }
                    TradeDirection tradeDirection = TradeDirection.parse(s[1]);
                    double m = Double.parseDouble(s[2]);
                    Config config = new Config(this,i,m,instrument,tradeDirection);
                    initEntity.add(config);
                }
            }
        }
    }

    final class Config extends InstrumentConfig{
        public Config(QuantStrategy strategy, int index, double m, Instrument instrument,TradeDirection td) {
            super(strategy, index, m, instrument,td);
        }
    }

    @Override
    public void onStopEx() {
        forexServiceProxy = null;
    }

    @Override
    protected void process(InstrumentConfig x, IBar bar) throws JFException {
    }

    @Override
    protected void dailyOpen(Instrument instrument, long time) throws JFException {
        calcYlzc();
    }

    /**
     * 计算压力支撑位
     */
    private void calcYlzc() {
        out("ylzc","计算压力支撑位");
    }

    @Override
    protected String getVersion() {
        return "100";
    }

    @Override
    protected String getName() {
        return "Yasha";
    }

    @Override
    protected void onTickEx(Instrument instrument, ITick tick) {
    }

    @Override
    protected void onBarEx(Instrument instrument, Period period, IBar askBar, IBar bidBar) {
    }

    @Override
    protected void onMessageEx(IMessage message) {
    }

    @Override
    protected void onAccountEx(IAccount account) {
    }
}
